import React, { useEffect, useState } from "react";
import { Button, Form, Input, Select } from "antd";
import axios from "axios";

const Modals = (props) => {
  const [form] = Form.useForm();

  useEffect(() => {
    if (props.title == "编辑") {
      form.setFieldsValue(props.objItem);
    }
  }, []);

  const onFinish = async (values: any) => {
    console.log(values);
    if (props.title == "添加") {
      let obj = {
        id: new Date().getTime(),
        ...values,
      };
      props.onCancel(obj);
    } else {
      let obj = {
        ...props.objItem,
        ...values,
        time: new Date().getTime(),
      };
      props.onOk(obj);
    }
  };

  return (
    <Form form={form} onFinish={onFinish} style={{ maxWidth: 600 }}>
      <Form.Item
        label="客户名称"
        name="name"
        rules={[
          {
            required: true,
            message: "请输入客户名称!",
          },
        ]}
      >
        <Select
          placeholder="客户名称"
          options={[
            {
              value: "深圳市腾讯计算机系统有限公司",
              label: "深圳市腾讯计算机系统有限公司",
            },
            {
              value: "深圳市亿恩科技有限公司",
              label: "深圳市亿恩科技有限公司",
            },
          ]}
        />
      </Form.Item>
      <Form.Item
        label="客户状态"
        name="khzt"
        rules={[
          {
            required: true,
            message: "请输入客户状态!",
          },
        ]}
      >
        <Select
          placeholder="客户状态"
          options={[
            { value: "已完成", label: "已完成" },
            { value: "未完成", label: "未完成" },
            { value: "待审核", label: "待审核" },
          ]}
        />
      </Form.Item>
      <Form.Item
        label="客户星级"
        name="khxj"
        rules={[
          {
            required: true,
            message: "请输入客户星级!",
          },
        ]}
      >
        <Select
          placeholder="客户星级"
          options={[
            { value: "1", label: "1" },
            { value: "2", label: "2" },
            { value: "3", label: "3" },
            { value: "4", label: "4" },
            { value: "5", label: "5" },
          ]}
        />
      </Form.Item>
      <Form.Item
        label="首联系人"
        name="lxr"
        rules={[
          {
            required: true,
            message: "请输入首联系人!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="手机号"
        name="phone"
        rules={[
          {
            required: true,
            message: "请输入手机号!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="更进天数"
        name="timefalse"
        rules={[
          {
            required: true,
            message: "请输入更进天数!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item>
        <Button type="primary" htmlType="submit">
          确定
        </Button>
      </Form.Item>
    </Form>
  );
};

export default Modals;
